package com.yiwei.zhh.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.CircleImageView;
import com.allen.library.SuperButton;
import com.bumptech.glide.Glide;
import com.yiwei.zhh.R;
import com.yiwei.zhh.adapter.base.ItemAdapter;
import com.yiwei.zhh.model.SpreadListsModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class MyExtensionAdapter extends ItemAdapter<SpreadListsModel.DataBean.ListsBean, MyExtensionAdapter.DefaultHolder> {


    private Context context;
    private String status = "1";

    public MyExtensionAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_my_extension, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {

        SpreadListsModel.DataBean.ListsBean item = getItem(position);
        if (item.images != null && item.images.size() != 0) {
            holder.list.setVisibility(View.VISIBLE);
            holder.list.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
            ExtensionPhotoAdapter adapter = new ExtensionPhotoAdapter(context);
            holder.list.setAdapter(adapter);
            adapter.update(item.images);
        } else {
            holder.list.setVisibility(View.GONE);
        }
        Glide.with(context).load(item.header).placeholder(R.mipmap.img_main_prize_icon).into(holder.imgIcon);
        holder.txtName.setText(item.real_name);
        holder.txtContent.setText(item.content);
        holder.txtTime.setText(item.times);
        switch (item.ftype_id) {
            case "4":
                holder.txtType.setShapeStrokeColor(0xff4C81FF).setUseShape();
                holder.txtType.setTextColor(0xff4C81FF);
                break;
            case "3":
                holder.txtType.setShapeStrokeColor(0xffFF7A31).setUseShape();
                holder.txtType.setTextColor(0xffFF7A31);
                break;
            case "1":
                holder.txtType.setShapeStrokeColor(0xff3BCF8F).setUseShape();
                holder.txtType.setTextColor(0xff3BCF8F);
                break;
            case "2":
                holder.txtType.setShapeStrokeColor(0xffFE5A59).setUseShape();
                holder.txtType.setTextColor(0xffFE5A59);
                break;
            case "9":
                holder.txtType.setShapeStrokeColor(0xffB6BCDB).setUseShape();
                holder.txtType.setTextColor(0xffB6BCDB);
                break;
        }
        holder.txtType.setText(item.ftype);

        if (status.equals("1") && Float.valueOf(item.prize_money) == 100) {
            holder.imgSign.setVisibility(View.VISIBLE);
            holder.txtStatus.setVisibility(View.GONE);
        } else if (status.equals("0")) {
            holder.imgSign.setVisibility(View.GONE);
            holder.txtStatus.setVisibility(View.VISIBLE);
            holder.txtStatus.setText("审核中");
            holder.txtStatus.setTextColor(0xffFF7A31);
            holder.txtStatus.setShapeStrokeColor(0xffFF7A31).setUseShape();
        } else if (status.equals("2")) {
            holder.imgSign.setVisibility(View.GONE);
            holder.txtStatus.setVisibility(View.VISIBLE);
            holder.txtStatus.setText("审核失败");
            holder.txtStatus.setTextColor(0xffFE5A59);
            holder.txtStatus.setShapeStrokeColor(0xffFE5A59).setUseShape();
        }else {
            holder.imgSign.setVisibility(View.GONE);
            holder.txtStatus.setVisibility(View.GONE);
        }
    }

    public void setStatus(String status) {
        this.status = status;
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        CircleImageView imgIcon;
        @BindView(R.id.txt_name)
        TextView txtName;
        @BindView(R.id.txt_time)
        TextView txtTime;
        @BindView(R.id.txt_type)
        SuperButton txtType;
        @BindView(R.id.txt_status)
        SuperButton txtStatus;
        @BindView(R.id.txt_content)
        TextView txtContent;
        @BindView(R.id.list)
        RecyclerView list;
        @BindView(R.id.img_sign)
        ImageView imgSign;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
